#include <stdio.h>
#include <string.h>
#include <stddef.h>
//指针步长: 指针变量+1 要向后跳多少个字节
//指针类型,不单单决定指针的步长,还决定解引用的时候从给定地址开始取类型大小的字节数
//指针类型在转换的时候就是步长发生了变化
void test01()
{
    char *p = NULL;
    printf("%d\n", p);
    printf("%d\n", p+1);

    int *p2 = NULL;
    printf("%d\n", p2);
    printf("%d\n", p2+1);

    char buf[1024] = {0};
    int a = 100;
    memcpy(buf+1,&a,sizeof(int));
    
    char* p3 = buf;
    printf("%d\n", *(int *)(p3+1)); //100
}
struct Person{
    int a;
    char b;
    char buf[64];
    int d;
};
void test02()
{
    struct Person p = {10, 'a', "hello world!", 100};
    printf("a off:%d\n", offsetof(struct Person, b)); //offsetof 计算偏移量 4
    printf("d = %d\n", *(int *)((char *)&p + offsetof(struct Person, d)) ); // 100取出来了
}
int main(int argc, char const *argv[])
{
    //test01();
    test02();
    return 0;
}